<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType = "text/html; charset=UTF-8" pageEncoding="utf-8" %>
<%@ include file="/common/init.jsp"%>
<html>
<head>
<title>澳斯浪廷会员平台</title>
<link href="<c:url value='/resources/css/css.css'/>" type="text/css" rel="stylesheet"/>
<script type="text/javascript" src="<c:url value='/resources/js/jquery-1.7.2.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/resources/js/validate.js'/>"></script>
<script type="text/javascript" src="<c:url value='/resources/js/MathUtil.js'/>"></script>
<script type="text/javascript" src="<c:url value='/resources/js/mask.js'/>"></script>
</head>
<body leftmargin="0">
<div class="main">
<div class="width_l">
    <iframe src="menu.action" frameborder="0" width="250" height="100%" class="menu"></iframe>
</div>    
    <div class="right">
    <div class="width_r">
        <div class="menu_r">
            <ul>
                <li><a href="index.action">首页</a></li>
                <li><a href="information.action">消息</a></li>
                <li><a href="notice.action">公告中心</a></li>
                <li><a href="news.action">新闻中心</a></li>
                <li><a href="inbox.action">收件箱</a></li>
                <li><a href="tomail.action">写邮件</a></li>
                <li><a href="sent.action">已发送</a></li>
                <li><a href="${ctx}/exit.action">安全退出</a></li> 
            </ul>
        </div>
        <div class="news_top"><img src="<c:url value='/resources/images/top.jpg'/>" /></div>
        <div class="news">
          <h4>兑换中心</h4>
          <div class="duihuan">
          <div class="doudou">
              <table width="260" border="0" cellspacing="0" cellpadding="0">
				  <tr>
				    <td class="cf_left">咖啡豆</td>
				    <td class="cf_right">
						${userAccount.bonusMoney} <input type="hidden" name="" value="${userAccount.bonusMoney }" id="bonusMoney"/>
						<input type="hidden" id="exStockAmount" value="${exStockAmount}"/>
					</td>
				  </tr>
				  <tr>
				    <td colspan="2" height="6"></td>
				    </tr>
				  <tr>
				    <td class="cf_left">激活豆</td>
				    <td class="cf_right">
						${userAccount.activMoney} <input type="hidden" name="" value="${userAccount.activMoney }" id="activMoney"/>
					</td>
				  </tr>
				  <tr>
				    <td colspan="2" height="6"></td>
				  </tr>
				  <tr>
				    <td class="cf_left">游戏豆</td>
				    <td class="cf_right">
						${userAccount.stockMoney} <input type="hidden" name="" value="${userAccount.stockMoney }" id="stockMoney"/>
					</td>
				  </tr>
				  <tr>
				    <td colspan="2" height="6"></td>
				  </tr>
				  <tr>
				    <td class="cf_left">仙草豆</td>
				    <td class="cf_right">
						${userAccount.consumerMoney} <input type="hidden" name="" value="${userAccount.consumerMoney }" id="consumerMoney"/>
					</td>
				  </tr>
				  <tr>
				    <td colspan="2" height="6"></td>
				  </tr>
				  <tr>
				    <td class="cf_left">V V 豆</td>
				    <td class="cf_right">
						${userAccount.additionMoney}
					</td>
				  </tr>
				 </table>
			</div>
              <form method="post" id="exchange">
              <div class="dh">
              	<table width="440" border="0" align="center" cellpadding="0" cellspacing="0">
				  <tr>
				    <td width="30">
				    	<input type="radio" name="exchangeType" id="radio" value="1"/>
				    </td>
				    <td width="188">
				    	<img src="<c:url value='/resources/images/zhuan_1.jpg'/>" />
				    </td>
				    <td width="30">
				    	<input type="radio" name="exchangeType" id="radio" value="2" />
				    </td>
				    <td width="192">
				    	<img src="<c:url value='/resources/images/zhuan_2.jpg'/>" />
				    </td>
				  </tr>
				  <tr>
				    <td height="60">
				    	<input type="radio" name="exchangeType" id="radio2" value="3" /></td>
				    <td>
				    	<img src="<c:url value='/resources/images/zhuan_3.jpg'/>" /></td>
				    <td>
				    	<input type="radio" name="exchangeType" id="radio2" value="4" /></td>
				    <td>
				    	<img src="<c:url value='/resources/images/zhuan_4.jpg'/>" /></td>
				  </tr>
				</table>
               <div class="srmm">
               	金额：<input name="exchangeAmount" id="exchangeAmount" class="text" type="text" />　　
               	请输入三级密码：<input name="thirdPassword" class="text" type="password" id="thirdPassword"/></div>
               <div class="dhtj"><img onclick="doExchange();" src="<c:url value='/resources/images/tijiao.jpg'/>" /></div>
          </div>
          <input type="hidden" id="stockExchange" value="${stockExchange}"/><!-- 已经转的金额 -->
          </form>
          </div>
	          <s:action name="exchangelist" executeResult="true" >
			  </s:action>
	        </div> 
	        <div class="news_down"><img src="<c:url value='/resources/images/down.jpg'/>" /></div>
	    </div>
	    </div>
	</div>

</body>
</html>
<script type="text/javascript">
function doExchange(){
	$.ajaxSetup({cache:false});
	var checkFlg = true;
	checkFlg = checkFlg && validateEmpty_jquery("金额", "exchangeAmount");
	checkFlg = checkFlg && validateNumber_jquery("金额 ", "exchangeAmount");
	checkFlg = checkFlg && validateEmpty_jquery("原来三级密码", "thirdPassword");
	//checkFlg = checkFlg && false;
	//$(document).mask("系统处理中，请稍后......");
	$.ajax({
		type:'POST',
		url: "${ctx}/chkTidPwd.action",
		data: "thirdPassword="+$("#thirdPassword").val(),
        async:false,  // 设置同步方式
        cache:false,
		dataType:"html",
		success: function(data,status){
			if($.trim(data)!=''){
				setValidateErrorStyle_jquery($("#thirdPassword"));
				alert(data);
				checkFlg = checkFlg && false;
			}
		},
		error: function(data,status,e){
			alert(e.name);
		}
	});
	var amount = $("#exchangeAmount").val();
	var stockExchange = $("#stockExchange").val();
	var exchangeType = $('input:radio[name="exchangeType"]:checked').val(); //兑换方式
	var exStockAmount = $("#exStockAmount").val();
	var maxAmount = 0;
	///alert(exchangeType);
	if("" == exchangeType || typeof(exchangeType)=='undefined'){
		alert("请选择兑换方式！");
		return false;
	}else if("1" == exchangeType){
			if(dcmSub(dcmAdd(amount,stockExchange),exStockAmount)>0){
				alert("累计兑换数量超过超过限定值 ！");
				return false;
			}else{
				maxAmount = $("#bonusMoney").val();
			}
	}else if("2"==exchangeType){
		maxAmount = $("#bonusMoney").val();
	}else if("3" == exchangeType){
		maxAmount = $("#activMoney").val();
	}else if("4" == exchangeType){
		maxAmount = $("#consumerMoney").val();
	}
	if(dcmSub(amount,maxAmount)>0){
		alert("您输入的金额超过账户余额，请重新填写！");
		$("#exchangeAmount").focus();
		return false;
	}
	if ( !checkFlg ) return false;
    if (checkFlg) {
    	//var data = $("#othermember").formSerialize();
    	//document.forms[0].action = "${ctx}/doexchange.action";
       // document.forms[0].submit();
        //兑换成功
        var data = $("#exchange").serialize();
        $(document).mask("系统处理中，请稍后......");
		jQuery.ajax({
			url: "${ctx}/doexchange.action",
			type: "post",
			dataType:"html",
			data:data,
			async:false,
			success: function(jsondata){
				alert(jsondata);
				window.location.href = "${ctx}/exchange.action";
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
		    }
		});
    }
}
</script>